#include <stl/set.h>
#include <standard/math.h>
#include "terrain/terrainobject.h"
#include "terrain/terrainblock.h"
#include "scene/sceneobjectnavigationmap.h"
#include "editorscenemgr.h"
#include "navigationeditcmd.h"

CNavigationEditCmd::CNavigationEditCmd( int32 nDataIndex, list< SNavigationDataInfo > *pNavigationEditInfoList ){
    m_nDataIndex = nDataIndex;
    m_vNavigationDataInfoList = *pNavigationEditInfoList;
}
CNavigationEditCmd::~CNavigationEditCmd(){

}
void CNavigationEditCmd::Init(){

}
void CNavigationEditCmd::Final(){

}
bool32 CNavigationEditCmd::Redo(){
    CSceneObjectNavigationMap* _pSceneObjectNavigationMap = m_pSceneMgr->GetSceneObjectNavigationMap();
    list< SNavigationDataInfo >::iterator it = m_vNavigationDataInfoList.begin();
    list< SNavigationDataInfo >::iterator it_end = m_vNavigationDataInfoList.end();
    for( ; it != it_end; it ++ ){
        SNavigationDataInfo* _pNavigationDataInfo = &(*it);
        SNavigationLayerDataInfo* _pNavigationInfo = _pSceneObjectNavigationMap->GetInfoItem( _pNavigationDataInfo->m_nX, _pNavigationDataInfo->m_nY );
        _pNavigationInfo[ m_nDataIndex ].m_nValue = _pNavigationDataInfo->m_nNewDataInfo;
        _pNavigationInfo[ m_nDataIndex ].m_cColor = _pNavigationDataInfo->m_cNewDataColor;
    }
    _pSceneObjectNavigationMap->UpdateTextureData();
    return True;
}
bool32 CNavigationEditCmd::Undo(){
    CSceneObjectNavigationMap* _pSceneObjectNavigationMap = m_pSceneMgr->GetSceneObjectNavigationMap();
    list< SNavigationDataInfo >::iterator it = m_vNavigationDataInfoList.begin();
    list< SNavigationDataInfo >::iterator it_end = m_vNavigationDataInfoList.end();
    for( ; it != it_end; it ++ ){
        SNavigationDataInfo* _pNavigationDataInfo = &(*it);
        SNavigationLayerDataInfo* _pNavigationInfo = _pSceneObjectNavigationMap->GetInfoItem( _pNavigationDataInfo->m_nX, _pNavigationDataInfo->m_nY );
        _pNavigationInfo[ m_nDataIndex ].m_nValue = _pNavigationDataInfo->m_nOldDataInfo;
        _pNavigationInfo[ m_nDataIndex ].m_cColor = _pNavigationDataInfo->m_cOldDataColor;
        
    }
    _pSceneObjectNavigationMap->UpdateTextureData();
    return True;
}